{extends file="index.tpl"}
{block name=head_title}LIST OF COFFEE SHOPS FOR SALES{/block}
{block name=head_script}
    <script>
        function checkSale(oForm) {
            if (oForm.cbbTrafficType.value === "" || oForm.cbbTrafficType.value === null ||
                oForm.txtQuantityTable.value === "" || oForm.txtQuantityTable.value === null ||
                oForm.txtQuantityLCD.value === "" || oForm.txtQuantityLCD.value === null ||
                oForm.txtPeopleWeek.value === "" || oForm.txtPeopleWeek.value === null ||
                oForm.txtPeopleDay.value === "" || oForm.txtPeopleDay.value === null ||
                oForm.txtViewerDay.value === "" || oForm.txtViewerDay.value === null)
            {
                alert("Bạn chưa nhập đầy đủ các thông tin!");
                return false;
            }
            else {
                return true;
            }
        }
    </script>
    {if $action == "edit" && isset($saleItem)}
        <script>
            $(document).ready(function() {
                $('#cbbTrafficType').val('{$saleItem.TrafficType}');
                $('#txtQuantityTable').val('{$saleItem.QuantityTable}');
                $('#txtQuantityLCD').val('{$saleItem.QuantityLCD}');
                $('#txtPeopleWeek').val('{$saleItem.PeopleWeek}');
                $('#txtPeopleDay').val('{$saleItem.PeopleDay}');
                $('#txtViewerDay').val('{$saleItem.ViewerDay}');

                $('#txtQuantityTable,#txtQuantityLCD,#txtPeopleWeek,#txtPeopleDay,#txtViewerDay').priceFormat({
                    centsLimit: false,
                    prefix: false,
                    limit: 7,
                });
            });

        </script>
    {/if}
{/block}
{block name=head_style}{/block}
{block name=body}
    {if isset($action)}
        {if $action == "edit" && isset($saleItem)}
            <!-- Table Edit -->
            <form id="frmSale" method="post" action="/sale/edit" onsubmit="return checkSale(this);">
                <table cellspacing="0" cellpadding="3" align="center" border="1" class="table">
                    <thead>
                        <tr class="table_thead_tr">
                            <th colspan="2">
                                Sửa thông tin Traffic quán {$saleItem.TenDD}
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Title</td>
                            <td>
                                {$saleItem.TenDD}
                            </td>
                        </tr>
                        <tr>
                            <td>Traffic Type</td>
                            <td> 
                                <select id="cbbTrafficType" name="cbbTrafficType" style="width:200px;">
                                    <option value="">--Chọn--</option>
                                    <option>High Street</option>
                                    <option>Shopping Mall</option>
                                    <option>Office Building</option>
                                    <option>Shopping Mall & Office</option>
                                    <option>Premium Resident</option>
                                    <option>Ben Thanh Market</option>
                                    <option>Plaza</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>Quantity of Table</td>
                            <td>
                                <input type="text" id="txtQuantityTable" name="txtQuantityTable" style="width: 196px"/>
                            </td>
                        </tr>
                        <tr>
                            <td>Quantity of LCD</td>
                            <td>
                                <input type="text" id="txtQuantityLCD" name="txtQuantityLCD" style="width: 196px"/>
                            </td>
                        </tr>
                        <tr>
                            <td>People / Week</td>
                            <td>
                                <input type="text" id="txtPeopleWeek" name="txtPeopleWeek" style="width: 196px"/>
                            </td>
                        </tr>
                        <tr>
                            <td>People / Day</td>
                            <td>
                                <input type="text" id="txtPeopleDay" name="txtPeopleDay" style="width: 196px"/>
                            </td>
                        </tr>
                        <tr>
                            <td>Viewer / Day</td>
                            <td>
                                <input type="text" id="txtViewerDay" name="txtViewerDay" style="width: 196px"/>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" style="text-align: center">
                                <input type="button" id="btnBack" name="btnBack" value="Back" onclick="" />

                                <input type="submit" id="submit" name="submit" value="Update" />
                            </td>
                        </tr>
                    <input type="hidden" id="maSI" name="maSI" value="{$saleItem.MaSI}" />
                    </tbody>
                </table>
            </form>
        {/if}
        {if $action == "view" && isset($saleView)}
            <a href="/sale/export" class="link_add_new">Save as file</a>
            <br />
            <br />
            <!-- Table View -->
            <table cellspacing="0" cellpadding="3" align="center" border="1" class="table">
                <thead>
                    <tr class="table_thead_tr">
                        <th colspan="12">
                            LIST OF COFFEE SHOPS
                        </th>
                    </tr>
                    <tr>
                        <th style="width: 25px;">No</th>
                        <th style="width: 132px;">Traffic Type</th>
                        <th style="">Title</th>
                        <th style="width: 170px;">Address</th>
                        <th style="width: 65px;">District</th>
                        <th style="width: 40px;">Area</th>
                        <th style="width: 60px;">Quantity Of Table</th>
                        <th style="width: 60px;">Quantity Of LCD</th>
                        <th style="width: 60px;">People / Week</th>
                        <th style="width: 60px;">People / Day</th>
                        <th style="width: 60px;">Viewer / Day</th>
                        <th style="width: 25px;">Edit</th>
                    </tr>
                </thead>
                <tbody style="font-size:90%;">
                    {foreach from=$saleView item=i}
                        <tr>
                            <td style="text-align: center">{$i@index + 1}</td>
                            <td style="text-align: left">{$i.TrafficType}</td>
                            <td style="text-align: left">{$i.TenDD}</td>
                            <td style="text-align: left">{$i.DiaChi}</td>
                            <td style="text-align: center">{$i.TenQH}</td>
                            <td style="text-align: center">{$i.TenTP}</td>
                            <td style="text-align: center">{$i.QuantityTable|number_format}</td>
                            <td style="text-align: center">{$i.QuantityLCD|number_format}</td>
                            <td style="text-align: center">{$i.PeopleWeek|number_format}</td>
                            <td style="text-align: center">{$i.PeopleDay|number_format}</td>
                            <td style="text-align: center">{$i.ViewerDay|number_format}</td>
                            <td style="text-align: center"><a href="/sale/edit/{$i.MaDD}">Edit</a></td>
                        </tr>
                    {/foreach}
                </tbody>
            </table>
        {/if}
    {/if}
    <!-- Hiện thông báo sau khi xử lý dữ liệu -->
    {if isset($success)}
        <span>
            {if $success==1}
                <p style="color:green">Thao tác thành công!</p>
            {/if}
            {if $success==-1}
                <p style="color:red">Thao tác thất bại vì dữ liệu bị trùng hoặc không tồn tại!</p>
            {/if}
            {if $success==0}
                <p style="color:red">Thao tác thất bại vì dữ liệu đang sử dụng!</p>
            {/if}
            <p>Đang chuyển đến trang "List of coffee shops" sau: <span id="redirect" style="color: red; font-weight: bold">3</span> giây. 
                Hoặc <a href="/sale/view">chuyển ngay</a>
            </p>
            <script>
                setTimeout(function() {
                    $("#redirect").text('' + 2);
                }, 1000);
                setTimeout(function() {
                    $("#redirect").text('' + 1);
                }, 2000);
                setTimeout(function() {
                    $("#redirect").text('' + 0);
                }, 3000);
                setTimeout(function() {
                    top.location.href = '/sale/view';
                }, 3500);
            </script>
        </span>
    {/if}
{/block}